package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.UploadFilesListDao;
import com.fdb.efp.nls.service.domain.UploadFilesList;
import com.fdb.efp.nls.service.facade.UploadFilesListService;
import com.fdb.efp.nls.service.vo.UploadFilesListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 文件上传清单服务实现
 *
 * @author gcb
 * @date 2019-12-27
 */
@Service("uploadFilesListService")
public class UploadFilesListServiceImpl implements UploadFilesListService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(UploadFilesListServiceImpl.class);

    @Autowired
    private UploadFilesListDao uploadFilesListDao;

    /**
     * 新增数据
     *
     * @param uploadFilesListVo
     * @return
     */
    @Override
    public int insert(UploadFilesListVO uploadFilesListVo) {
        logger.debug("当前新增数据为:" + uploadFilesListVo.toString());
        int num = 0;
        try {
            UploadFilesList uploadFilesList = new UploadFilesList();
            beanCopy(uploadFilesListVo, uploadFilesList);
            num = uploadFilesListDao.insert(uploadFilesList);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param uploadFilesListVo
     * @return
     */
    @Override
    public int deleteByPk(UploadFilesListVO uploadFilesListVo) {
        logger.debug("当前删除数据条件为:" + uploadFilesListVo);
        int num = 0;
        try {
            UploadFilesList uploadFilesList = new UploadFilesList();
            beanCopy(uploadFilesListVo, uploadFilesList);
            num = uploadFilesListDao.deleteByPk(uploadFilesList);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + uploadFilesListVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param uploadFilesListVo
     * @return
     */
    @Override
    public int updateByPk(UploadFilesListVO uploadFilesListVo) {
        logger.debug("当前修改数据为:" + uploadFilesListVo.toString());
        int num = 0;
        try {
            UploadFilesList uploadFilesList = new UploadFilesList();
            beanCopy(uploadFilesListVo, uploadFilesList);
            num = uploadFilesListDao.updateByPk(uploadFilesList);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + uploadFilesListVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inUploadFilesListVo
     * @return
     */
    @Override
    public UploadFilesListVO queryByPk(UploadFilesListVO inUploadFilesListVo) {
        logger.debug("当前查询参数信息为:" + inUploadFilesListVo);
        try {
            UploadFilesList queryUploadFilesList = new UploadFilesList();
            beanCopy(inUploadFilesListVo, queryUploadFilesList);
            UploadFilesList queryRslUploadFilesList = uploadFilesListDao.queryByPk(queryUploadFilesList);
            if (Objects.nonNull(queryRslUploadFilesList)) {
                return beanCopy(queryRslUploadFilesList, new UploadFilesListVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public List<UploadFilesListVO> queryByConditions(UploadFilesListVO uploadFilesListVO) {
        logger.debug("当前查询参数信息为:" + uploadFilesListVO);
        List<UploadFilesListVO> list = null;
        try {
            List<UploadFilesListVO> queryRslUploadFilesList = uploadFilesListDao.queryByConditionsByPage(uploadFilesListVO);
            pageSet(queryRslUploadFilesList,uploadFilesListVO);
            list = (List<UploadFilesListVO>) beansCopy(queryRslUploadFilesList, UploadFilesListVO.class);
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return list;
    }
}
